﻿Imports System.Data.OleDb

Public Class AddCricketGround
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub
    Protected Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(fuProfilePicture.FileName)
        If fuProfilePicture.HasFile Then
            fuProfilePicture.SaveAs(Server.MapPath("~/Pictures/Grounds") & "/" & newFileName)
        End If

        Dim p1 As New OleDbParameter("@f1", txtStadiumName.Text)
        Dim p2 As New OleDbParameter("@f2", txtAddress.Text)
        Dim p3 As New OleDbParameter("@f3", txtCity.Text)
        Dim p4 As New OleDbParameter("@f4", txtPostCode.Text)
        Dim p5 As New OleDbParameter("@f5", txtCountry.Text)
        Dim p6 As New OleDbParameter("@f6", txtPhoneNumber.Text)
        Dim p7 As New OleDbParameter("@f7", "Pictures/Grounds" & "/" & newFileName)
        Dim p8 As New OleDbParameter("@f8", txtURL.Text)
        Dim p9 As New OleDbParameter("@f9", User.Identity.Name)
        Dim p10 As New OleDbParameter("@f10", Format(Date.Now(), "dd/MM/yyyy hh:mm:ss tt"))
        Dim sql As String = "insert into CricketGrounds(StadiumName,Address,City,PostCode,Country,PhoneNumber,Picture,URL,CreatedBy,CreatedDate) values (@f1,@f2,@f3,@4,@f5,@f6,@f7,@f8,@f9,@f10)"
        DataAccessLayer.ExecuteNonQuery(sql, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
        Dim sql2 As String = "Update userprofile set PostedInfo= PostedInfo+1 where username =@f9"
        DataAccessLayer.ExecuteNonQuery(sql2, p9)

        Dim body As String = " <h2> Update from Cricket Forum !</h2><p> Hello, " & User.Identity.Name & " has added new International Cricket Stadium " & txtStadiumName.Text & " <p> Please Visit the site for more information!</p>  <p> Thanks!<br />Cricket Forum</p>"
        GeneralMethods.SendMail(User.Identity.Name & " has Added New Stadium", body)
        Response.Redirect("~/CricStadium.aspx")
    End Sub
    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class